#pragma once

#include <string.h>

#include <string>

#include "../core.h"
#include "qbkernel/include/qb_base.h"
#include "qbprotocol/include/ssLoginProto.h"

#define kLoginConnect 0x0001  // 登录网络连接状态
#define kHttpKernel 0x0002    // http事件

#pragma warning(disable : 4251)
namespace qb {
enum LoginProxyType {
  LoginProxyType_kProxyNone,
  LoginProxyType_kProxyBrowser,
  LoginProxyType_kProxyHttp,
  LoginProxyType_kProxySocksVer4 = 4,
  LoginProxyType_kProxySocksVer5,
};

struct S_CORE_EXPORT LoginProxyInfo {
  LoginProxyInfo() {
    nProxyType = LoginProxyType_kProxyNone;
    bUse = false;
    nProxyPort = 0;
  }
  LoginProxyInfo& operator=(const LoginProxyInfo& info) {
    strProxyHost = info.strProxyHost;
    strUsername = info.strUsername;
    strPassword = info.strPassword;
    strDomain = info.strDomain;
    nProxyPort = info.nProxyPort;
    nProxyType = info.nProxyType;
    bUse = info.bUse;

    return *this;
  }
  std::string strProxyHost;
  std::string strUsername;
  std::string strPassword;
  std::string strDomain;
  LoginProxyType nProxyType;
  uint16_t nProxyPort;
  bool bUse;
};

/*< ip/port */
struct S_CORE_EXPORT tIPAdressPort {
  tIPAdressPort() {
    strIPAdress = "";
    uPort = 0;
  }
  std::string strIPAdress;
  uint32_t uPort;
};

/*< 用户基本信息 */
struct S_CORE_EXPORT tUserData {
  std::string strUserID;       // 用户ID
  std::string strAccount;      // 账号
  std::string strRawPassword;  // 原始密码
  std::string strPassword;     // 密码
  std::string strCookie;       // cookie
  std::string strCompanyId;    // companyid
  std::string strMac;          // mac地址
};

class S_CORE_EXPORT loginData {
 public:
  static loginData& instance();

 public:
  int32_t& ConnectID();

  const tIPAdressPort& GetServerLoginAddress() const;
  void SetServerLoginAddress(const std::string& strIP, uint32_t uPort);

  const tIPAdressPort& GetGatewayLoginAddress() const;
  void SetGatewayLoginAddress(const std::string& strIP, uint32_t uPort);

  const LoginProxyInfo& GetProxyInfo() const;
  void SetProxyInfo(LoginProxyInfo& proxy);

  NetStatus GetCurrentStatus() const;
  void SetCurrentStatus(NetStatus eStatus);

  void SetLoginAck(const xLoginLgnSvrProAck_t& ack);
  xLoginLgnSvrProAck_t& GetLoginAck();

  void SetReLogin(bool bReLogin);

  bool IsLoggedin() const;
  bool IsLoginning() const;
  bool IsReLogin() const;

  void ResetLoginData();

  tUserData& UserInfo();

 private:
  loginData();
  ~loginData();

  void ResetLoginAck();

 private:
  int32_t m_connect_id;
  tUserData m_UserData;
  tIPAdressPort m_serverAddressPort;
  tIPAdressPort m_gatewayAddressPort;
  LoginProxyInfo m_proxy;
  NetStatus m_eStatus;
  xLoginLgnSvrProAck_t m_xLgnAckBody;
  bool m_bReLogin;
};

}  // namespace qb